<?php

namespace app\data\controller;

use app\data\model\LiveAppList;
use app\data\model\LiveOpinionList;
use app\data\model\LiveUserList;
use think\admin\Controller;
use think\admin\model\SystemUser;

/**
 * 建议列表
 * Class OpinionListController
 * @package app\data\controller
 */
class OpinionListController extends Controller
{
    /**
     * 查询
     * @auth true  # 表示需要验证权限
     * @menu true  # 添加系统菜单节点
     * @login true # 强制登录才可访问
     */
    public function index()
    {
        $this->title = '建议列表';

        $this->sysusers = SystemUser::mk()->field('id,nickname')->select()->toArray();
        $this->apps = LiveAppList::mk()->field('app_id,app_name')->select()->toArray();
        $this->users = LiveUserList::mk()->field('id,user_nickname')->select()->toArray();

        $this->type = $this->request->get('type', 'index');
        $query = LiveOpinionList::mQuery();
        if ($this->type === 'index') $query->where(['deleted' => 0,'opinion_type'=>0]);
        elseif ($this->type === 'handle') $query->where(['deleted' => 0,'opinion_type'=>1]);
        elseif ($this->type === 'recycle') $query->where(['deleted' => 1]);
        else $this->error("无法加载 {$this->type} 数据列表！");

        $query->dateBetween('create_time');
        $query->order('create_time asc')->page();
    }
    /**
     * 设置处理状态
     * @auth true  # 表示需要验证权限
     * @menu true  # 添加系统菜单节点
     * @login true # 强制登录才可访问
     */
    public function opiniontype()
    {
        LiveOpinionList::mSave($this->_vali([
            'opinion_type.in:0,1'  => '状态值范围异常！',
            'opinion_type.require' => '状态值不能为空！',
        ]), 'id');
    }
    /**
     * 删除
     * @auth true  # 表示需要验证权限
     * @menu true  # 添加系统菜单节点
     * @login true # 强制登录才可访问
     */
    public function remove()
    {
        LiveOpinionList::mSave($this->_vali([
            'deleted.in:0,1' => '状态值范围异常！',
            'deleted.require' => '状态值不能为空！',
        ]), 'id');
    }
}